﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.IO;

namespace servidor
{
    class GestorSerialize
    {
        private string path = "c:/certificados/listaUtilizadores.txt";

         /// <summary>
        /// Load
        /// </summary>
        public List<Utilizador> Load()
        {

            List<Utilizador> novo = new List<Utilizador>();

            XmlSerializer serializer = new XmlSerializer(novo.GetType());
            using (FileStream readFileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                object obj = serializer.Deserialize(readFileStream);
                novo = (List<Utilizador>)obj;
                readFileStream.Close();
                return novo;
                 //raffleCouponClient = ((ConfigRaffle)obj)._raffleCouponClient;
                 //raffleCoupon = ((ConfigRaffle)obj)._raffleCoupon;
                
            }
        }
 
        /// <summary>
        /// Save
        /// </summary>
        public void Save(List<Utilizador> lista)
        {
            
            XmlSerializer serializer = new XmlSerializer(lista.GetType());
            using (TextWriter writeFileStream = new StreamWriter(path))
            {
                serializer.Serialize(writeFileStream, lista);
                writeFileStream.Close();
            }
        }
    }
}
